<?php

function d() {
	$args= func_get_args();
	foreach ($args as $key => $value) {
		echo '<pre>';
		print_r($value);
		echo '</pre>';
	}
}

function trace() {
	$args=debug_backtrace();
    echo '<pre>';

    foreach ($args as $key => $value) {
        $result = '';
        $result .= isset($value['file']) ? $value['file'] . ' ' : null;
        $result .= isset($value['class']) ? $value['class'] . ' ': null;
        $result .= isset($value['line']) ? $value['line'] . ' ': null;

	   echo $result;
    }
	echo '</pre>';
}

function module_autoload($class) {
	$classPath = explode('_',$class);
	$classPath = implode (DIRECTORY_SEPARATOR, $classPath);
	$includePath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . $classPath . '.php';
	if (file_exists($includePath))
		include $includePath;
}

function library_autoload($class) {
	$classPath = explode('_',$class);
	$classPath = implode (DIRECTORY_SEPARATOR, $classPath);
	$includePath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . $classPath . '.php';
	if (file_exists($includePath))
		include $includePath;
}

// Код обработчика ошибок SQL.
function databaseErrorHandler($message, $info)
{
    // Если использовалась @, ничего не делать.
    if (!error_reporting()) return;
    // Выводим подробную информацию об ошибке.
    echo "SQL Error: $message<br><pre>"; 
    print_r($info);
    echo "</pre>";
    exit();
}

spl_autoload_register('module_autoload');
spl_autoload_register('library_autoload');
